layui.use(['form','layer','laydate','table','laytpl'],function(){
    var form = layui.form,
        $ = layui.jquery,
        table = layui.table,
        layer = layui.layer;

    //文档价格
    table.render({
        elem: '#myTable',
        url : '/iprint/admin/getPriceTable?title=photo',
        method:'get',
        page:false,
        response: {
            statusName: 'status' //数据状态的字段名称，默认：code
            ,statusCode: 200 //成功的状态码，默认：0
            ,countName: 'totalCount' //数据总数的字段名称，默认：count
            ,dataName: 'list' //数据列表的字段名称，默认：data
        },
        cellMinWidth : 95,
        limit : 30,
        id : "myTable",
        cols : [[
            {field:"id", title: 'ID', width: 60, fixed:"left",sort:"true", align:'center', edit: 'text'},
            {field: 'printType', title: '打印类型', align:'center'},
            {field: 'pageSize', title: '照片尺寸',  align:'center'},
            {field: 'craftwork', title: '所用工艺', sort:"true", align:'center'},
            {field: 'price', title: '每张价格',sort:"true", align:'center'},
            {title: '操作',minWidth:100, templet:'#edit',fixed:"right",align:"center"}
        ]]
    });

    table.on('tool(priceEdit)', function(obj){
        var data = obj.data; //获得当前行数据
        layer.prompt({
            formType: 3,
            value: data.price,
            title: '请输入价格',
        }, function(value, index, elem){
            $.ajax({
                cache:true,
                type:"GET",
                url: "/iprint/admin/updatePrice?title=photo&id="+data.id+"&price="+value,
                async: true,
                success: function(data) {
                    if(data == 'OK'){
                        obj.update({price: value});
                        layer.msg("修改成功！");
                    }else{
                        layer.msg("修改失败！");
                    }
                }
            });
            layer.close(index);
        });
    });
})